package com.ysd.lis.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.lis.entity.SysJob;
import com.ysd.lis.entity.lab.LabRptGroup;
import com.ysd.lis.entity.qi.QiIndexSqlData;
import com.ysd.lis.entity.qi.QiJobVsMainitem;
import com.ysd.lis.service.qi.QiIndexSqlDataService;
import com.ysd.lis.service.qi.QiJobVsMainitemService;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 标本可接受性
 *
 * @author wanghao
 * @create 2024/7/15 0015
 */
@Component("sample")
public class SampleAcceptability {
    @Autowired
    private QiJobVsMainitemService qiJobVsMainitemService;
    @Autowired
    private QiIndexSqlDataService qiIndexSqlDataService;
    @Autowired
    private Scheduler scheduler;

    public void acceptability(String jobName) {

        //1.查看指标项目是否有维护
        MPJLambdaWrapper<QiJobVsMainitem> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(QiJobVsMainitem.class);
        queryWrapper.leftJoin(SysJob.class, SysJob::getId, QiJobVsMainitem::getJobId);
        //queryWrapper.eq(SysJob::getInvokeTarget, "sample.acceptability");
        queryWrapper.eq(SysJob::getJobName,jobName);
        queryWrapper.eq(QiJobVsMainitem::getDelFlag, 0);
        List<QiJobVsMainitem> list = qiJobVsMainitemService.list(queryWrapper);
        //2.循环遍历项目
        if (CollectionUtils.isNotEmpty(list)) {
            for (QiJobVsMainitem qiJobVsMainitem : list) {
                QiIndexSqlData qiIndexSqlData = new QiIndexSqlData();
                qiIndexSqlData.setIndexId(qiJobVsMainitem.getIndexId());
                qiIndexSqlData.setItemId(qiJobVsMainitem.getItemId());
                qiIndexSqlData.setIsJob(true);
                qiIndexSqlDataService.synQiIndexSqlData(qiIndexSqlData);
            }
        }
    }
}
